package com.gyl.query;

import java.util.ArrayList;
import java.util.List;

/**  
* @Name: PageResult
* @Description: 分页处理Bean，封装查询后的分页结果
* @Author: 李超
* @Create Date: 2011-06-25
*/
public class PageResult<T> {
	
	private int currentPage ; //主表当前页码
	private int currentPage_zib ; //子表当前页码
	private int pageSize ; //每页显示记录数
	private int totalRows ; //总记录数
	private int totalPages ; //总页数，计算得出
	private List<T> rows = new ArrayList<T>() ; //当前分页记录
	
	public PageResult() { }
	
	public PageResult(int currentPage, int pageSize, int totalRows) {
		this.currentPage = currentPage ;
		this.pageSize = pageSize ;
		this.totalRows = totalRows ;
		
		//设置当前页码和总页数最小值必须为1，Math.max(a,b)，返回a与b中的较大值
		this.currentPage = Math.max(this.currentPage, 1) ;
		this.totalPages = Math.max(this.totalRows, 1) ;
		
		//计算总页数
		this.totalPages = (this.totalRows + this.pageSize - 1) / this.pageSize ;
		
		//设置当前页码不能大于总页数，Math.min(a,b)，返回a与b中的较小值
		this.currentPage = Math.min(this.currentPage, this.totalPages) ;
		
	}
	
	public int getCurrentPage_zib() {
		return currentPage_zib;
	}
	public void setCurrentPage_zib(int currentPage_zib) {
		this.currentPage_zib = currentPage_zib;
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotalRows() {
		return totalRows;
	}
	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}
	public int getTotalPages() {
		return totalPages;
	}
	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}
	public List<T> getRows() {
		return rows;
	}
	public void setRows(List<T> rows) {
		this.rows = rows;
	}

	@Override
	public String toString() {
		return "PageResult [currentPage=" + currentPage + ", currentPage_zib="
				+ currentPage_zib + ", pageSize=" + pageSize + ", totalRows="
				+ totalRows + ", totalPages=" + totalPages + ", rows=" + rows
				+ "]";
	}
	
}
